import { createStore, combineReducers, applyMiddleware } from './myredux'
// import thunk from 'redux-thunk'
import thunk from './mythunk'
import logger from './logger'
console.log(thunk)
let initState = { count: 100 }
function reducer(state, action) {
  state = state || initState
  switch (action.type) {
    case 'add':
      return {
        count: state.count + action.num
      }
    case 'minus':
      return {
        count: state.count - action.num
      }
    default:
      return {
        ...state
      }
  }
}
function color(state = { color: 'red' }, action) {
  if (action.type == 'changeColor') {
    return {
      color: action.col
    }
  } else {
    return {
      ...state
    }
  }
}
let rootReducer = combineReducers({
  count: reducer,
  color: color
})
export default createStore(rootReducer, applyMiddleware(thunk, logger))